package StudyCode.summary.Basic.mystring;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class StringContainChinese {
	public static void main(String[] args) {
		String str = "哈喽a";
		String str1 = "Hello";
		System.out.println(str +":含有中文?——" + isContainChinese(str));
		System.out.println(str1 +":含有中文?——" + isContainChinese(str1));
	}

	private static boolean isContainChinese(String s) {
		for (int i = 0; i < s.length(); i++) {
			if (isChinese(s.charAt(i))) {
				return true;
			}
		}
		return false;
	}

	private static boolean isChinese(char c) {
		Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(c);
		return unicodeBlock == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || unicodeBlock == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
				|| unicodeBlock == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || unicodeBlock == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
				|| unicodeBlock == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || unicodeBlock == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
				|| unicodeBlock == Character.UnicodeBlock.GENERAL_PUNCTUATION;
	}
}
